<?php

/**
 * This is the model class for table "xman_schedule".
 *
 * The followings are the available columns in table 'xman_schedule':
 * @property integer $schedule_id
 * @property string $schedule_subject
 * @property string $schedule_description
 * @property string $schedule_status
 * @property string $schedule_type
 * @property string $schedule_created_date
 * @property string $schedule_updated_date
 * @property string $schedule_deleted_date
 * @property integer $schedule_project_id
 * @property integer $schedule_created_by_user_id
 *
 * The followings are the available model relations:
 * @property Event[] $events
 * @property Meeting[] $meetings
 * @property Project $scheduleProject
 * @property User $scheduleCreatedByUser
 */
class Schedule extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Schedule the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_schedule';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('schedule_subject, schedule_project_id, schedule_created_by_user_id', 'required'),
			array('schedule_project_id, schedule_created_by_user_id', 'numerical', 'integerOnly'=>true),
			array('schedule_subject', 'length', 'max'=>50),
			array('schedule_description, schedule_status', 'length', 'max'=>100),
			array('schedule_type', 'length', 'max'=>20),
			array('schedule_created_date, schedule_updated_date, schedule_deleted_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('schedule_id, schedule_subject, schedule_description, schedule_status, schedule_type, schedule_created_date, schedule_updated_date, schedule_deleted_date, schedule_project_id, schedule_created_by_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'events' => array(self::HAS_MANY, 'Event', 'event_schedule_id'),
			'meetings' => array(self::HAS_MANY, 'Meeting', 'meeting_schedule_id'),
			'scheduleProject' => array(self::BELONGS_TO, 'Project', 'schedule_project_id'),
			'scheduleCreatedByUser' => array(self::BELONGS_TO, 'User', 'schedule_created_by_user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'schedule_id' => 'Schedule',
			'schedule_subject' => 'Schedule Subject',
			'schedule_description' => 'Schedule Description',
			'schedule_status' => 'Schedule Status',
			'schedule_type' => 'Schedule Type',
			'schedule_created_date' => 'Schedule Created Date',
			'schedule_updated_date' => 'Schedule Updated Date',
			'schedule_deleted_date' => 'Schedule Deleted Date',
			'schedule_project_id' => 'Schedule Project',
			'schedule_created_by_user_id' => 'Schedule Created By User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('schedule_id',$this->schedule_id);
		$criteria->compare('schedule_subject',$this->schedule_subject,true);
		$criteria->compare('schedule_description',$this->schedule_description,true);
		$criteria->compare('schedule_status',$this->schedule_status,true);
		$criteria->compare('schedule_type',$this->schedule_type,true);
		$criteria->compare('schedule_created_date',$this->schedule_created_date,true);
		$criteria->compare('schedule_updated_date',$this->schedule_updated_date,true);
		$criteria->compare('schedule_deleted_date',$this->schedule_deleted_date,true);
		$criteria->compare('schedule_project_id',$this->schedule_project_id);
		$criteria->compare('schedule_created_by_user_id',$this->schedule_created_by_user_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}